
<!DOCTYPE html>
<html lang="zh-cn" itemscope itemtype="http://schema.org/WebPage">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Go 每日一库之 go-homedir - 大俊的博客</title>


    <meta name="renderer" content="webkit" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes"/>

    <meta name="MobileOptimized" content="width"/>
    <meta name="HandheldFriendly" content="true"/>


    <meta name="applicable-device" content="pc,mobile">

    <meta name="theme-color" content="#f8f5ec" />
    <meta name="msapplication-navbutton-color" content="#f8f5ec">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">

    <meta name="mobile-web-app-capable" content="yes">

    <meta name="author" content="darjun" />
    <meta name="description" content="简介 今天我们来看一个很小，很实用的库go-homedir。顾名思义，go-homedir用来获取用户的主目录。 实际上，使用标准库os/use" />

    <meta name="keywords" content="大俊, 大俊的博客, go, golang, gopher" />






    <meta name="generator" content="Hugo 0.83.1" />


    <link rel="canonical" href="https://darjun.github.io/2020/01/14/godailylib/go-homedir/" />





    <link rel="icon" href="/favicon.ico" />











    <link rel="stylesheet" href="/sass/jane.min.fa3d941d1d0e0ddc985804227feabffea55c89883eb0af34e0532a7ae9135151.css" integrity="sha256-&#43;j2UHR0ODdyYWAQif&#43;q//qVciYg&#43;sK804FMqeukTUVE=" media="screen" crossorigin="anonymous">




    <link rel="stylesheet" href="/css/custom.css">


    <meta property="og:title" content="Go 每日一库之 go-homedir" />
    <meta property="og:description" content="简介 今天我们来看一个很小，很实用的库go-homedir。顾名思义，go-homedir用来获取用户的主目录。 实际上，使用标准库os/use" />
    <meta property="og:type" content="article" />
    <meta property="og:url" content="https://darjun.github.io/2020/01/14/godailylib/go-homedir/" /><meta property="article:section" content="post" />
    <meta property="article:published_time" content="2020-01-14T07:33:05&#43;00:00" />
    <meta property="article:modified_time" content="2020-01-14T07:33:05&#43;00:00" />

    <meta itemprop="name" content="Go 每日一库之 go-homedir">
    <meta itemprop="description" content="简介 今天我们来看一个很小，很实用的库go-homedir。顾名思义，go-homedir用来获取用户的主目录。 实际上，使用标准库os/use"><meta itemprop="datePublished" content="2020-01-14T07:33:05&#43;00:00" />
    <meta itemprop="dateModified" content="2020-01-14T07:33:05&#43;00:00" />
    <meta itemprop="wordCount" content="1615">
    <meta itemprop="keywords" content="Go 每日一库," /><meta name="twitter:card" content="summary"/>
    <meta name="twitter:title" content="Go 每日一库之 go-homedir"/>
    <meta name="twitter:description" content="简介 今天我们来看一个很小，很实用的库go-homedir。顾名思义，go-homedir用来获取用户的主目录。 实际上，使用标准库os/use"/>

    <!--[if lte IE 9]>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
    <![endif]-->

    <!--[if lt IE 9]>
    <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->


    <script type="application/javascript">
        var doNotTrack = false;
        if (!doNotTrack) {
            window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
            ga('create', 'UA-42862533-1', 'auto');

            ga('send', 'pageview');
        }
    </script>
    <script async src='https://www.google-analytics.com/analytics.js'></script>



</head>
<body>
<div id="mobile-navbar" class="mobile-navbar">
    <div class="mobile-header-logo">
        <a href="/" class="logo">大俊</a>
    </div>
    <div class="mobile-navbar-icon">
        <span></span>
        <span></span>
        <span></span>
    </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
    <ul class="mobile-menu-list">
        <li class="mobile-menu-item">



            <a class="menu-item-link" href="https://darjun.github.io/">首页</a>


        </li><li class="mobile-menu-item">



            <a class="menu-item-link" href="https://darjun.github.io/post/">归档</a>


        </li><li class="mobile-menu-item">



            <a class="menu-item-link" href="https://darjun.github.io/tags/">标签</a>


        </li><li class="mobile-menu-item">



            <a class="menu-item-link" href="https://darjun.github.io/categories/">分类</a>


        </li><li class="mobile-menu-item">



            <a class="menu-item-link" href="https://darjun.github.io/about/">关于我</a>


        </li><li class="mobile-menu-item">



            <a class="menu-item-link" href="https://github.com/darjun" rel="noopener" target="_blank">
                Github

                <i class="iconfont">
                    <svg class="icon" viewBox="0 0 1024 1024" version="1.1"
                         xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
                         width="18" height="18">
                        <path d="M623.36 272.96 473.216 423.04C467.2 429.056 467.072 438.656 472.896 444.416c0 0-6.72-6.656 1.6 1.6C496.064 467.648 528.64 500.224 528.64 500.224 534.464 506.048 544 505.856 550.016 499.904l150.08-150.144 67.328 66.432c9.024 8.96 27.456 4.544 30.4-8.96 19.968-92.608 46.656-227.52 46.656-227.52 6.848-34.496-16.192-56.704-49.92-49.92 0 0-134.656 26.816-227.328 46.784C560.32 178.048 556.352 182.272 554.752 187.136c-3.2 6.208-3.008 14.208 3.776 20.992L623.36 272.96z"></path>
                        <path d="M841.152 457.152c-30.528 0-54.784 24.512-54.784 54.656l0 274.752L237.696 786.56 237.696 237.696l206.016 0c6.656 0 10.752 0 13.248 0C487.68 237.696 512 213.184 512 182.848 512 152.32 487.36 128 456.96 128L183.04 128C153.216 128 128 152.576 128 182.848c0 3.136 0.256 6.272 0.768 9.28C128.256 195.136 128 198.272 128 201.408l0 639.488c0 0.064 0 0.192 0 0.256 0 0.128 0 0.192 0 0.32 0 30.528 24.512 54.784 54.784 54.784l646.976 0c6.592 0 9.728 0 11.712 0 28.736 0 52.928-22.976 54.464-51.968C896 843.264 896 842.304 896 841.344l0-20.352L896 561.408 896 512.128C896 481.792 871.424 457.152 841.152 457.152z"></path>
                    </svg>

                </i>
            </a>


        </li>



    </ul>
</nav>










<link rel="stylesheet" href="/lib/photoswipe/photoswipe.min.css" />
<link rel="stylesheet" href="/lib/photoswipe/default-skin/default-skin.min.css" />




<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <div class="pswp__bg"></div>

    <div class="pswp__scroll-wrap">

        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <div class="pswp__ui pswp__ui--hidden">
            <div class="pswp__top-bar">

                <div class="pswp__counter"></div>
                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
                <button class="pswp__button pswp__button--share" title="Share"></button>
                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>


                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>
            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>
            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>
            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>
        </div>
    </div>
</div>







<header id="header" class="header container">
    <div class="logo-wrapper">
        <a href="/" class="logo">

            大俊

        </a>
    </div>

    <nav class="site-navbar">
        <ul id="menu" class="menu">


            <li class="menu-item">



                <a class="menu-item-link" href="https://darjun.github.io/">首页</a>




            </li>

            <li class="menu-item">



                <a class="menu-item-link" href="https://darjun.github.io/post/">归档</a>




            </li>

            <li class="menu-item">



                <a class="menu-item-link" href="https://darjun.github.io/tags/">标签</a>




            </li>

            <li class="menu-item">



                <a class="menu-item-link" href="https://darjun.github.io/categories/">分类</a>




            </li>

            <li class="menu-item">



                <a class="menu-item-link" href="https://darjun.github.io/about/">关于我</a>




            </li>

            <li class="menu-item">



                <a class="menu-item-link" href="https://github.com/darjun" rel="noopener" target="_blank">
                    Github

                    <i class="iconfont">
                        <svg class="icon" viewBox="0 0 1024 1024" version="1.1"
                             xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
                             width="18" height="18">
                            <path d="M623.36 272.96 473.216 423.04C467.2 429.056 467.072 438.656 472.896 444.416c0 0-6.72-6.656 1.6 1.6C496.064 467.648 528.64 500.224 528.64 500.224 534.464 506.048 544 505.856 550.016 499.904l150.08-150.144 67.328 66.432c9.024 8.96 27.456 4.544 30.4-8.96 19.968-92.608 46.656-227.52 46.656-227.52 6.848-34.496-16.192-56.704-49.92-49.92 0 0-134.656 26.816-227.328 46.784C560.32 178.048 556.352 182.272 554.752 187.136c-3.2 6.208-3.008 14.208 3.776 20.992L623.36 272.96z"></path>
                            <path d="M841.152 457.152c-30.528 0-54.784 24.512-54.784 54.656l0 274.752L237.696 786.56 237.696 237.696l206.016 0c6.656 0 10.752 0 13.248 0C487.68 237.696 512 213.184 512 182.848 512 152.32 487.36 128 456.96 128L183.04 128C153.216 128 128 152.576 128 182.848c0 3.136 0.256 6.272 0.768 9.28C128.256 195.136 128 198.272 128 201.408l0 639.488c0 0.064 0 0.192 0 0.256 0 0.128 0 0.192 0 0.32 0 30.528 24.512 54.784 54.784 54.784l646.976 0c6.592 0 9.728 0 11.712 0 28.736 0 52.928-22.976 54.464-51.968C896 843.264 896 842.304 896 841.344l0-20.352L896 561.408 896 512.128C896 481.792 871.424 457.152 841.152 457.152z"></path>
                        </svg>

                    </i>
                </a>




            </li>






        </ul>
    </nav>

</header>

<div id="mobile-panel">
    <main id="main" class="main bg-llight">
        <div class="content-wrapper">
            <div id="content" class="content container">
                <article class="post bg-white">

                    <header class="post-header">
                        <h1 class="post-title">Go 每日一库之 go-homedir</h1>

                        <div class="post-meta">
                            <time datetime="2020-01-14" class="post-time">
                                2020-01-14
                            </time>
                            <div class="post-category">
                                <a href="https://darjun.github.io/categories/go/"> Go </a>

                            </div>
                            <span class="more-meta"> 约 1615 字 </span>
                            <span class="more-meta"> 预计阅读 4 分钟 </span>



                            <span id="busuanzi_container_page_pv">
            | 阅读 <span id="busuanzi_value_page_pv"></span>
          </span>




                        </div>
                    </header>



                    <div class="post-toc" id="post-toc">
                        <h2 class="post-toc-title">文章目录</h2>
                        <div class="post-toc-content">
                            <nav id="TableOfContents">
                                <ul>
                                    <li><a href="#简介">简介</a></li>
                                    <li><a href="#快速使用">快速使用</a></li>
                                    <li><a href="#高级用法">高级用法</a></li>
                                    <li><a href="#实现">实现</a></li>
                                    <li><a href="#参考">参考</a></li>
                                    <li><a href="#我">我</a></li>
                                </ul>
                            </nav>
                        </div>
                    </div>


                    <div class="post-content">
                        <h2 id="简介">简介</h2>
                        <p>今天我们来看一个很小，很实用的库<a href="https://github.com/mitchellh/go-homedir">go-homedir</a>。顾名思义，<code>go-homedir</code>用来获取用户的主目录。
                            实际上，使用标准库<code>os/user</code>我们也可以得到这个信息：</p>
                        <div class="highlight"><div class="chroma">
                                <table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span></code></pre></td>
                                        <td class="lntd">
<pre class="chroma"><code class="language-golang" data-lang="golang"><span class="kn">package</span> <span class="nx">main</span>

<span class="kn">import</span> <span class="p">(</span>
  <span class="s">&#34;fmt&#34;</span>
  <span class="s">&#34;log&#34;</span>
  <span class="s">&#34;os/user&#34;</span>
<span class="p">)</span>

<span class="kd">func</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
  <span class="nx">u</span><span class="p">,</span> <span class="nx">err</span> <span class="o">:=</span> <span class="nx">user</span><span class="p">.</span><span class="nf">Current</span><span class="p">()</span>
  <span class="k">if</span> <span class="nx">err</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
    <span class="nx">log</span><span class="p">.</span><span class="nf">Fatal</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span>
  <span class="p">}</span>

  <span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="s">&#34;Home dir:&#34;</span><span class="p">,</span> <span class="nx">u</span><span class="p">.</span><span class="nx">HomeDir</span><span class="p">)</span>
<span class="p">}</span>
</code></pre></td></tr></table>
                            </div>
                        </div><p>那么为什么还要<code>go-homedir</code>库？</p>
                        <p>在 Darwin 系统上，标准库<code>os/user</code>的使用需要 cgo。所以，任何使用<code>os/user</code>的代码都不能交叉编译。
                            但是，大多数人使用<code>os/user</code>的目的仅仅只是想获取主目录。因此，<code>go-homedir</code>库出现了。</p>
                        <h2 id="快速使用">快速使用</h2>
                        <p><code>go-homedir</code>是第三方包，使用前需要先安装：</p>
                        <div class="highlight"><div class="chroma">
                                <table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
                                        <td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">$ go get github.com/mitchellh/go-homedir
</code></pre></td></tr></table>
                            </div>
                        </div><p>使用非常简单：</p>
                        <div class="highlight"><div class="chroma">
                                <table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span></code></pre></td>
                                        <td class="lntd">
<pre class="chroma"><code class="language-golang" data-lang="golang"><span class="kn">package</span> <span class="nx">main</span>

<span class="kn">import</span> <span class="p">(</span>
  <span class="s">&#34;fmt&#34;</span>
  <span class="s">&#34;log&#34;</span>

  <span class="s">&#34;github.com/mitchellh/go-homedir&#34;</span>
<span class="p">)</span>

<span class="kd">func</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
  <span class="nx">dir</span><span class="p">,</span> <span class="nx">err</span> <span class="o">:=</span> <span class="nx">homedir</span><span class="p">.</span><span class="nf">Dir</span><span class="p">()</span>
  <span class="k">if</span> <span class="nx">err</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
    <span class="nx">log</span><span class="p">.</span><span class="nf">Fatal</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span>
  <span class="p">}</span>

  <span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="s">&#34;Home dir:&#34;</span><span class="p">,</span> <span class="nx">dir</span><span class="p">)</span>

  <span class="nx">dir</span> <span class="p">=</span> <span class="s">&#34;~/golang/src&#34;</span>
  <span class="nx">expandedDir</span><span class="p">,</span> <span class="nx">err</span> <span class="o">:=</span> <span class="nx">homedir</span><span class="p">.</span><span class="nf">Expand</span><span class="p">(</span><span class="nx">dir</span><span class="p">)</span>
  <span class="k">if</span> <span class="nx">err</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
    <span class="nx">log</span><span class="p">.</span><span class="nf">Fatal</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span>
  <span class="p">}</span>

  <span class="nx">fmt</span><span class="p">.</span><span class="nf">Printf</span><span class="p">(</span><span class="s">&#34;Expand of %s is: %s\n&#34;</span><span class="p">,</span> <span class="nx">dir</span><span class="p">,</span> <span class="nx">expandedDir</span><span class="p">)</span>
<span class="p">}</span>
</code></pre></td></tr></table>
                            </div>
                        </div><p><code>go-homedir</code>有两个功能：</p>
                        <ul>
                            <li><code>Dir</code>：获取用户主目录；</li>
                            <li><code>Expand</code>：将路径中的第一个<code>~</code>扩展成用户主目录。</li>
                        </ul>
                        <h2 id="高级用法">高级用法</h2>
                        <p>由于<code>Dir</code>的调用可能涉及一些系统调用和外部执行命令，多次调用费性能。所以<code>go-homedir</code>提供了缓存的功能。默认情况下，缓存是开启的。
                            我们也可以将<code>DisableCache</code>设置为<code>false</code>来关闭它。</p>
                        <div class="highlight"><div class="chroma">
                                <table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span></code></pre></td>
                                        <td class="lntd">
<pre class="chroma"><code class="language-golang" data-lang="golang"><span class="kn">package</span> <span class="nx">main</span>

<span class="kn">import</span> <span class="p">(</span>
  <span class="s">&#34;fmt&#34;</span>
  <span class="s">&#34;log&#34;</span>

  <span class="s">&#34;github.com/mitchellh/go-homedir&#34;</span>
<span class="p">)</span>

<span class="kd">func</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
  <span class="nx">homedir</span><span class="p">.</span><span class="nx">DisableCache</span> <span class="p">=</span> <span class="kc">false</span>

  <span class="nx">dir</span><span class="p">,</span> <span class="nx">err</span> <span class="o">:=</span> <span class="nx">homedir</span><span class="p">.</span><span class="nf">Dir</span><span class="p">()</span>
  <span class="k">if</span> <span class="nx">err</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
    <span class="nx">log</span><span class="p">.</span><span class="nf">Fatal</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span>
  <span class="p">}</span>

  <span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="s">&#34;Home dir:&#34;</span><span class="p">,</span> <span class="nx">dir</span><span class="p">)</span>
<span class="p">}</span>
</code></pre></td></tr></table>
                            </div>
                        </div><p>使用缓存时，如果程序运行中修改了主目录，再次调用<code>Dir</code>还是返回之前的目录。如果需要获取最新的主目录，可以先调用<code>Reset</code>清除缓存。</p>
                        <h2 id="实现">实现</h2>
                        <p><code>go-homedir</code>源码只有一个文件<a href="https://github.com/mitchellh/go-homedir/blob/master/homedir.go">homedir.go</a>，今天我们大概看一下<code>Dir</code>的实现，去掉缓存相关代码：</p>
                        <div class="highlight"><div class="chroma">
                                <table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span></code></pre></td>
                                        <td class="lntd">
<pre class="chroma"><code class="language-golang" data-lang="golang"><span class="kd">func</span> <span class="nf">Dir</span><span class="p">()</span> <span class="p">(</span><span class="kt">string</span><span class="p">,</span> <span class="kt">error</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">var</span> <span class="nx">result</span> <span class="kt">string</span>
  <span class="kd">var</span> <span class="nx">err</span> <span class="kt">error</span>
  <span class="k">if</span> <span class="nx">runtime</span><span class="p">.</span><span class="nx">GOOS</span> <span class="o">==</span> <span class="s">&#34;windows&#34;</span> <span class="p">{</span>
    <span class="nx">result</span><span class="p">,</span> <span class="nx">err</span> <span class="p">=</span> <span class="nf">dirWindows</span><span class="p">()</span>
  <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
    <span class="c1">// Unix-like system, so just assume Unix
</span><span class="c1"></span>    <span class="nx">result</span><span class="p">,</span> <span class="nx">err</span> <span class="p">=</span> <span class="nf">dirUnix</span><span class="p">()</span>
  <span class="p">}</span>

  <span class="k">if</span> <span class="nx">err</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
    <span class="k">return</span> <span class="s">&#34;&#34;</span><span class="p">,</span> <span class="nx">err</span>
  <span class="p">}</span>
  <span class="k">return</span> <span class="nx">result</span><span class="p">,</span> <span class="kc">nil</span>
<span class="p">}</span>
</code></pre></td></tr></table>
                            </div>
                        </div><p>判断当前的系统是<code>windows</code>还是类 Unix，分别调用不同的方法。先看 windows 的，比较简单：</p>
                        <div class="highlight"><div class="chroma">
                                <table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span></code></pre></td>
                                        <td class="lntd">
<pre class="chroma"><code class="language-golang" data-lang="golang"><span class="kd">func</span> <span class="nf">dirWindows</span><span class="p">()</span> <span class="p">(</span><span class="kt">string</span><span class="p">,</span> <span class="kt">error</span><span class="p">)</span> <span class="p">{</span>
	<span class="c1">// First prefer the HOME environmental variable
</span><span class="c1"></span>	<span class="k">if</span> <span class="nx">home</span> <span class="o">:=</span> <span class="nx">os</span><span class="p">.</span><span class="nf">Getenv</span><span class="p">(</span><span class="s">&#34;HOME&#34;</span><span class="p">);</span> <span class="nx">home</span> <span class="o">!=</span> <span class="s">&#34;&#34;</span> <span class="p">{</span>
		<span class="k">return</span> <span class="nx">home</span><span class="p">,</span> <span class="kc">nil</span>
	<span class="p">}</span>

	<span class="c1">// Prefer standard environment variable USERPROFILE
</span><span class="c1"></span>	<span class="k">if</span> <span class="nx">home</span> <span class="o">:=</span> <span class="nx">os</span><span class="p">.</span><span class="nf">Getenv</span><span class="p">(</span><span class="s">&#34;USERPROFILE&#34;</span><span class="p">);</span> <span class="nx">home</span> <span class="o">!=</span> <span class="s">&#34;&#34;</span> <span class="p">{</span>
		<span class="k">return</span> <span class="nx">home</span><span class="p">,</span> <span class="kc">nil</span>
	<span class="p">}</span>

	<span class="nx">drive</span> <span class="o">:=</span> <span class="nx">os</span><span class="p">.</span><span class="nf">Getenv</span><span class="p">(</span><span class="s">&#34;HOMEDRIVE&#34;</span><span class="p">)</span>
	<span class="nx">path</span> <span class="o">:=</span> <span class="nx">os</span><span class="p">.</span><span class="nf">Getenv</span><span class="p">(</span><span class="s">&#34;HOMEPATH&#34;</span><span class="p">)</span>
	<span class="nx">home</span> <span class="o">:=</span> <span class="nx">drive</span> <span class="o">+</span> <span class="nx">path</span>
	<span class="k">if</span> <span class="nx">drive</span> <span class="o">==</span> <span class="s">&#34;&#34;</span> <span class="o">||</span> <span class="nx">path</span> <span class="o">==</span> <span class="s">&#34;&#34;</span> <span class="p">{</span>
		<span class="k">return</span> <span class="s">&#34;&#34;</span><span class="p">,</span> <span class="nx">errors</span><span class="p">.</span><span class="nf">New</span><span class="p">(</span><span class="s">&#34;HOMEDRIVE, HOMEPATH, or USERPROFILE are blank&#34;</span><span class="p">)</span>
	<span class="p">}</span>

	<span class="k">return</span> <span class="nx">home</span><span class="p">,</span> <span class="kc">nil</span>
<span class="p">}</span>
</code></pre></td></tr></table>
                            </div>
                        </div><p>流程如下：</p>
                        <ul>
                            <li>读取环境变量<code>HOME</code>，如果不为空，返回这个值；</li>
                            <li>读取环境变量<code>USERPROFILE</code>，如果不为空，返回这个值；</li>
                            <li>读取环境变量<code>HOMEDRIVE</code>和<code>HOMEPATH</code>，如果两者都不为空，拼接这两个值返回。</li>
                        </ul>
                        <p>类 Unix 系统的实现稍微复杂一点：</p>
                        <div class="highlight"><div class="chroma">
                                <table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span><span class="lnt">39
</span><span class="lnt">40
</span><span class="lnt">41
</span><span class="lnt">42
</span><span class="lnt">43
</span><span class="lnt">44
</span><span class="lnt">45
</span><span class="lnt">46
</span><span class="lnt">47
</span><span class="lnt">48
</span><span class="lnt">49
</span><span class="lnt">50
</span><span class="lnt">51
</span><span class="lnt">52
</span><span class="lnt">53
</span><span class="lnt">54
</span><span class="lnt">55
</span><span class="lnt">56
</span><span class="lnt">57
</span><span class="lnt">58
</span></code></pre></td>
                                        <td class="lntd">
<pre class="chroma"><code class="language-golang" data-lang="golang"><span class="kd">func</span> <span class="nf">dirUnix</span><span class="p">()</span> <span class="p">(</span><span class="kt">string</span><span class="p">,</span> <span class="kt">error</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">homeEnv</span> <span class="o">:=</span> <span class="s">&#34;HOME&#34;</span>
  <span class="k">if</span> <span class="nx">runtime</span><span class="p">.</span><span class="nx">GOOS</span> <span class="o">==</span> <span class="s">&#34;plan9&#34;</span> <span class="p">{</span>
    <span class="c1">// On plan9, env vars are lowercase.
</span><span class="c1"></span>    <span class="nx">homeEnv</span> <span class="p">=</span> <span class="s">&#34;home&#34;</span>
  <span class="p">}</span>

  <span class="c1">// First prefer the HOME environmental variable
</span><span class="c1"></span>  <span class="k">if</span> <span class="nx">home</span> <span class="o">:=</span> <span class="nx">os</span><span class="p">.</span><span class="nf">Getenv</span><span class="p">(</span><span class="nx">homeEnv</span><span class="p">);</span> <span class="nx">home</span> <span class="o">!=</span> <span class="s">&#34;&#34;</span> <span class="p">{</span>
    <span class="k">return</span> <span class="nx">home</span><span class="p">,</span> <span class="kc">nil</span>
  <span class="p">}</span>

  <span class="kd">var</span> <span class="nx">stdout</span> <span class="nx">bytes</span><span class="p">.</span><span class="nx">Buffer</span>

  <span class="c1">// If that fails, try OS specific commands
</span><span class="c1"></span>  <span class="k">if</span> <span class="nx">runtime</span><span class="p">.</span><span class="nx">GOOS</span> <span class="o">==</span> <span class="s">&#34;darwin&#34;</span> <span class="p">{</span>
    <span class="nx">cmd</span> <span class="o">:=</span> <span class="nx">exec</span><span class="p">.</span><span class="nf">Command</span><span class="p">(</span><span class="s">&#34;sh&#34;</span><span class="p">,</span> <span class="s">&#34;-c&#34;</span><span class="p">,</span> <span class="s">`dscl -q . -read /Users/&#34;$(whoami)&#34; NFSHomeDirectory | sed &#39;s/^[^ ]*: //&#39;`</span><span class="p">)</span>
    <span class="nx">cmd</span><span class="p">.</span><span class="nx">Stdout</span> <span class="p">=</span> <span class="o">&amp;</span><span class="nx">stdout</span>
    <span class="k">if</span> <span class="nx">err</span> <span class="o">:=</span> <span class="nx">cmd</span><span class="p">.</span><span class="nf">Run</span><span class="p">();</span> <span class="nx">err</span> <span class="o">==</span> <span class="kc">nil</span> <span class="p">{</span>
      <span class="nx">result</span> <span class="o">:=</span> <span class="nx">strings</span><span class="p">.</span><span class="nf">TrimSpace</span><span class="p">(</span><span class="nx">stdout</span><span class="p">.</span><span class="nf">String</span><span class="p">())</span>
      <span class="k">if</span> <span class="nx">result</span> <span class="o">!=</span> <span class="s">&#34;&#34;</span> <span class="p">{</span>
        <span class="k">return</span> <span class="nx">result</span><span class="p">,</span> <span class="kc">nil</span>
      <span class="p">}</span>
    <span class="p">}</span>
  <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
    <span class="nx">cmd</span> <span class="o">:=</span> <span class="nx">exec</span><span class="p">.</span><span class="nf">Command</span><span class="p">(</span><span class="s">&#34;getent&#34;</span><span class="p">,</span> <span class="s">&#34;passwd&#34;</span><span class="p">,</span> <span class="nx">strconv</span><span class="p">.</span><span class="nf">Itoa</span><span class="p">(</span><span class="nx">os</span><span class="p">.</span><span class="nf">Getuid</span><span class="p">()))</span>
    <span class="nx">cmd</span><span class="p">.</span><span class="nx">Stdout</span> <span class="p">=</span> <span class="o">&amp;</span><span class="nx">stdout</span>
    <span class="k">if</span> <span class="nx">err</span> <span class="o">:=</span> <span class="nx">cmd</span><span class="p">.</span><span class="nf">Run</span><span class="p">();</span> <span class="nx">err</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
      <span class="c1">// If the error is ErrNotFound, we ignore it. Otherwise, return it.
</span><span class="c1"></span>      <span class="k">if</span> <span class="nx">err</span> <span class="o">!=</span> <span class="nx">exec</span><span class="p">.</span><span class="nx">ErrNotFound</span> <span class="p">{</span>
        <span class="k">return</span> <span class="s">&#34;&#34;</span><span class="p">,</span> <span class="nx">err</span>
      <span class="p">}</span>
    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
      <span class="k">if</span> <span class="nx">passwd</span> <span class="o">:=</span> <span class="nx">strings</span><span class="p">.</span><span class="nf">TrimSpace</span><span class="p">(</span><span class="nx">stdout</span><span class="p">.</span><span class="nf">String</span><span class="p">());</span> <span class="nx">passwd</span> <span class="o">!=</span> <span class="s">&#34;&#34;</span> <span class="p">{</span>
        <span class="c1">// username:password:uid:gid:gecos:home:shell
</span><span class="c1"></span>        <span class="nx">passwdParts</span> <span class="o">:=</span> <span class="nx">strings</span><span class="p">.</span><span class="nf">SplitN</span><span class="p">(</span><span class="nx">passwd</span><span class="p">,</span> <span class="s">&#34;:&#34;</span><span class="p">,</span> <span class="mi">7</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="nx">passwdParts</span><span class="p">)</span> <span class="p">&gt;</span> <span class="mi">5</span> <span class="p">{</span>
          <span class="k">return</span> <span class="nx">passwdParts</span><span class="p">[</span><span class="mi">5</span><span class="p">],</span> <span class="kc">nil</span>
        <span class="p">}</span>
      <span class="p">}</span>
    <span class="p">}</span>
  <span class="p">}</span>

  <span class="c1">// If all else fails, try the shell
</span><span class="c1"></span>  <span class="nx">stdout</span><span class="p">.</span><span class="nf">Reset</span><span class="p">()</span>
  <span class="nx">cmd</span> <span class="o">:=</span> <span class="nx">exec</span><span class="p">.</span><span class="nf">Command</span><span class="p">(</span><span class="s">&#34;sh&#34;</span><span class="p">,</span> <span class="s">&#34;-c&#34;</span><span class="p">,</span> <span class="s">&#34;cd &amp;&amp; pwd&#34;</span><span class="p">)</span>
  <span class="nx">cmd</span><span class="p">.</span><span class="nx">Stdout</span> <span class="p">=</span> <span class="o">&amp;</span><span class="nx">stdout</span>
  <span class="k">if</span> <span class="nx">err</span> <span class="o">:=</span> <span class="nx">cmd</span><span class="p">.</span><span class="nf">Run</span><span class="p">();</span> <span class="nx">err</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
    <span class="k">return</span> <span class="s">&#34;&#34;</span><span class="p">,</span> <span class="nx">err</span>
  <span class="p">}</span>

  <span class="nx">result</span> <span class="o">:=</span> <span class="nx">strings</span><span class="p">.</span><span class="nf">TrimSpace</span><span class="p">(</span><span class="nx">stdout</span><span class="p">.</span><span class="nf">String</span><span class="p">())</span>
  <span class="k">if</span> <span class="nx">result</span> <span class="o">==</span> <span class="s">&#34;&#34;</span> <span class="p">{</span>
    <span class="k">return</span> <span class="s">&#34;&#34;</span><span class="p">,</span> <span class="nx">errors</span><span class="p">.</span><span class="nf">New</span><span class="p">(</span><span class="s">&#34;blank output when reading home directory&#34;</span><span class="p">)</span>
  <span class="p">}</span>

  <span class="k">return</span> <span class="nx">result</span><span class="p">,</span> <span class="kc">nil</span>
<span class="p">}</span>
</code></pre></td></tr></table>
                            </div>
                        </div><p>流程如下：</p>
                        <ul>
                            <li>先读取环境变量<code>HOME</code>（注意 plan9 系统上为<code>home</code>），如果不为空，返回这个值；</li>
                            <li>使用<code>getnet</code>命令查看系统的数据库中的相关记录，我们知道<code>passwd</code>文件中存储了用户信息，包括用户的主目录。使用<code>getent</code>命令查看<code>passwd</code>中当前用户的那条记录，然后从中找到主目录部分返回；</li>
                            <li>如果上一个步骤失败了，我们知道<code>cd</code>后不加参数是直接切换到用户主目录的，而<code>pwd</code>可以显示当前目录。那么就可以结合这两个命令返回主目录。</li>
                        </ul>
                        <p><strong>这里分析源码并不是表示使用任何库都要熟悉它的源码，毕竟使用库就是为了方便开发。</strong>
                            <strong>但是源码是我们学习和提高的一个非常重要的途径。我们在使用库遇到问题的时候也要有能力从文档或甚至源码中查找原因。</strong></p>
                        <h2 id="参考">参考</h2>
                        <ol>
                            <li><a href="https://github.com/mitchellh/go-homedir">home-dir</a> GitHub 仓库</li>
                        </ol>
                        <h2 id="我">我</h2>
                        <p><a href="https://darjun.github.io">我的博客</a></p>
                        <p>欢迎关注我的微信公众号【GoUpUp】，共同学习，一起进步~</p>
                        <p><img src="/img/wxgzh8.jpg#center" alt=""></p>

                    </div>



                    <div class="post-copyright">
                        <p class="copyright-item">
                            <span class="item-title">文章作者</span>
                            <span class="item-content">darjun</span>
                        </p>
                        <p class="copyright-item">
                            <span class="item-title">上次更新</span>
                            <span class="item-content">
      2020-01-14

    </span>
                        </p>

                        <p class="copyright-item">
                            <span class="item-title">许可协议</span>
                            <span class="item-content"><a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank">CC BY-NC-ND 4.0</a></span>
                        </p>
                    </div>





                    <footer class="post-footer">
                        <div class="post-tags">

                        </div>


                        <nav class="post-nav">

                            <a class="prev" href="/2020/01/15/godailylib/go-ini/">

                                <i class="iconfont">
                                    <svg  class="icon" viewBox="0 0 1024 1024" version="1.1"
                                          xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
                                          width="18" height="18">
                                        <path d="M691.908486 949.511495l75.369571-89.491197c10.963703-12.998035 10.285251-32.864502-1.499144-44.378743L479.499795 515.267417 757.434875 204.940602c11.338233-12.190647 11.035334-32.285311-0.638543-44.850487l-80.46666-86.564541c-11.680017-12.583596-30.356378-12.893658-41.662889-0.716314L257.233596 494.235404c-11.332093 12.183484-11.041474 32.266891 0.657986 44.844348l80.46666 86.564541c1.772366 1.910513 3.706415 3.533476 5.750981 4.877077l306.620399 321.703933C662.505829 963.726242 680.945807 962.528973 691.908486 949.511495z"></path>
                                    </svg>

                                </i>
                                <span class="prev-text nav-default">Go 每日一库之 go-ini</span>
                                <span class="prev-text nav-mobile">上一篇</span>
                            </a>

                            <a class="next" href="/2020/01/13/goweb/fileserver/">
                                <span class="next-text nav-default">Go Web 编程之 静态文件</span>
                                <span class="prev-text nav-mobile">下一篇</span>

                                <i class="iconfont">
                                    <svg class="icon" viewBox="0 0 1024 1024" version="1.1"
                                         xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
                                         width="18" height="18">
                                        <path d="M332.091514 74.487481l-75.369571 89.491197c-10.963703 12.998035-10.285251 32.864502 1.499144 44.378743l286.278095 300.375162L266.565125 819.058374c-11.338233 12.190647-11.035334 32.285311 0.638543 44.850487l80.46666 86.564541c11.680017 12.583596 30.356378 12.893658 41.662889 0.716314l377.434212-421.426145c11.332093-12.183484 11.041474-32.266891-0.657986-44.844348l-80.46666-86.564541c-1.772366-1.910513-3.706415-3.533476-5.750981-4.877077L373.270379 71.774697C361.493148 60.273758 343.054193 61.470003 332.091514 74.487481z"></path>
                                    </svg>

                                </i>
                            </a>
                        </nav>
                    </footer>
                </article>











                <div class="post bg-white">
                    <script src="https://utteranc.es/client.js"
                            repo= "darjun/blog-comments"
                            issue-term="pathname"
                            theme="github-light"
                            crossorigin="anonymous"
                            async>
                    </script>
                </div>












            </div>
        </div>
    </main>

    <footer id="footer" class="footer">
        <div class="icon-links">


            <a href="mailto:leedarjun@gmail.com" rel="me noopener" class="iconfont"
               title="email" >
                <svg class="icon" viewBox="0 0 1451 1024" version="1.1"
                     xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
                     width="36" height="36">
                    <path d="M664.781909 681.472759 0 97.881301C0 3.997201 71.046997 0 71.046997 0L474.477909 0 961.649408 0 1361.641813 0C1361.641813 0 1432.688811 3.997201 1432.688811 97.881301L771.345323 681.472759C771.345323 681.472759 764.482731 685.154773 753.594283 688.65053L753.594283 688.664858C741.602731 693.493018 729.424896 695.068979 718.077952 694.839748 706.731093 695.068979 694.553173 693.493018 682.561621 688.664858L682.561621 688.65053C671.644501 685.140446 664.781909 681.472759 664.781909 681.472759L664.781909 681.472759ZM718.063616 811.603883C693.779541 811.016482 658.879232 802.205449 619.10784 767.734955 542.989056 701.759633 0 212.052267 0 212.052267L0 942.809523C0 942.809523 0 1024 83.726336 1024L682.532949 1024 753.579947 1024 1348.948139 1024C1432.688811 1024 1432.688811 942.809523 1432.688811 942.809523L1432.688811 212.052267C1432.688811 212.052267 893.138176 701.759633 817.019477 767.734955 777.248 802.205449 742.347691 811.03081 718.063616 811.603883L718.063616 811.603883Z"></path>
                </svg>

            </a>

            <a href="https://github.com/darjun" rel="me noopener" class="iconfont"
               title="github"  target="_blank"
            >
                <svg class="icon" style="" viewBox="0 0 1024 1024" version="1.1"
                     xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
                     width="36" height="36">
                    <path d="M512 12.672c-282.88 0-512 229.248-512 512 0 226.261333 146.688 418.133333 350.08 485.76 25.6 4.821333 34.986667-11.008 34.986667-24.618667 0-12.16-0.426667-44.373333-0.64-87.04-142.421333 30.890667-172.458667-68.693333-172.458667-68.693333C188.672 770.986667 155.008 755.2 155.008 755.2c-46.378667-31.744 3.584-31.104 3.584-31.104 51.413333 3.584 78.421333 52.736 78.421333 52.736 45.653333 78.293333 119.850667 55.68 149.12 42.581333 4.608-33.109333 17.792-55.68 32.426667-68.48-113.706667-12.8-233.216-56.832-233.216-253.013333 0-55.893333 19.84-101.546667 52.693333-137.386667-5.76-12.928-23.04-64.981333 4.48-135.509333 0 0 42.88-13.738667 140.8 52.48 40.96-11.392 84.48-17.024 128-17.28 43.52 0.256 87.04 5.888 128 17.28 97.28-66.218667 140.16-52.48 140.16-52.48 27.52 70.528 10.24 122.581333 5.12 135.509333 32.64 35.84 52.48 81.493333 52.48 137.386667 0 196.693333-119.68 240-233.6 252.586667 17.92 15.36 34.56 46.762667 34.56 94.72 0 68.522667-0.64 123.562667-0.64 140.202666 0 13.44 8.96 29.44 35.2 24.32C877.44 942.592 1024 750.592 1024 524.672c0-282.752-229.248-512-512-512"></path>
                </svg>

            </a>


            <a href="https://darjun.github.io/index.xml" rel="noopener alternate" type="application/rss&#43;xml"
               class="iconfont" title="rss" target="_blank">
                <svg class="icon" viewBox="0 0 1024 1024" version="1.1"
                     xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
                     width="30" height="30">
                    <path d="M819.157333 1024C819.157333 574.592 449.408 204.8 0 204.8V0c561.706667 0 1024 462.293333 1024 1024h-204.842667zM140.416 743.04a140.8 140.8 0 0 1 140.501333 140.586667A140.928 140.928 0 0 1 140.074667 1024C62.72 1024 0 961.109333 0 883.626667s62.933333-140.544 140.416-140.586667zM678.784 1024h-199.04c0-263.210667-216.533333-479.786667-479.744-479.786667V345.173333c372.352 0 678.784 306.517333 678.784 678.826667z"></path>
                </svg>

            </a>

        </div>

        <div class="copyright">
  <span class="power-by">
    Powered by <a class="hexo-link" href="https://gohugo.io">Hugo</a>
  </span>
            <span class="division">|</span>
            <span class="theme-info">
    Theme - <a class="theme-link" href="https://github.com/xianmin/hugo-theme-jane">Jane</a>
  </span>

            <span class="copyright-year">
    &copy;

      2018 -
    2021
    <span class="heart">

      <i class="iconfont">
        <svg class="icon" viewBox="0 0 1025 1024" version="1.1"
             xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
             width="14" height="14">
  <path d="M1000.1 247.9c-15.5-37.3-37.6-70.6-65.7-98.9-54.4-54.8-125.8-85-201-85-85.7 0-166 39-221.4 107.4C456.6 103 376.3 64 290.6 64c-75.1 0-146.5 30.4-201.1 85.6-28.2 28.5-50.4 61.9-65.8 99.3-16 38.8-24 79.9-23.6 122.2 0.7 91.7 40.1 177.2 108.1 234.8 3.1 2.6 6 5.1 8.9 7.8 14.9 13.4 58 52.8 112.6 102.7 93.5 85.5 209.9 191.9 257.5 234.2 7 6.1 15.8 9.5 24.9 9.5 9.2 0 18.1-3.4 24.9-9.5 34.5-30.7 105.8-95.9 181.4-165 74.2-67.8 150.9-138 195.8-178.2 69.5-57.9 109.6-144.4 109.9-237.3 0.1-42.5-8-83.6-24-122.2z"
        fill="#8a8a8a"></path>
</svg>

      </i>
    </span><span class="author">
        大俊

      </span></span>



            <span id="busuanzi_container">
      访客数/访问量：<span id="busuanzi_value_site_uv"></span>/<span id="busuanzi_value_site_pv"></span>
    </span>



        </div>

    </footer>

    <div class="back-to-top" id="back-to-top">
        <i class="iconfont">

            <svg class="icon" viewBox="0 0 1024 1024" version="1.1"
                 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
                 width="35" height="35">
                <path d="M510.866688 227.694839 95.449397 629.218702l235.761562 0-2.057869 328.796468 362.40389 0L691.55698 628.188232l241.942331-3.089361L510.866688 227.694839zM63.840492 63.962777l894.052392 0 0 131.813095L63.840492 195.775872 63.840492 63.962777 63.840492 63.962777zM63.840492 63.962777"></path>
            </svg>

        </i>
    </div>
</div>

<script type="text/javascript" src="/lib/jquery/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="/lib/slideout/slideout-1.0.1.min.js"></script>




<script type="text/javascript" src="/js/main.638251f4230630f0335d8c6748e53a96f94b72670920b60c09a56fdc8bece214.js" integrity="sha256-Y4JR9CMGMPAzXYxnSOU6lvlLcmcJILYMCaVv3Ivs4hQ=" crossorigin="anonymous"></script>













<script type="text/javascript" src="/js/load-photoswipe.js"></script>
<script type="text/javascript" src="/lib/photoswipe/photoswipe.min.js"></script>
<script type="text/javascript" src="/lib/photoswipe/photoswipe-ui-default.min.js"></script>





<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>












</body>
</html>
